﻿
(function ($) {
    app.modals.CreateOrEditStorageModal = function () {

        var _modalManager;

        var _storageService = abp.services.app.storage;

		//$(".maxlength-handler").maxlength({
        //    limitReachedClass: "label label-danger",
        //    alwaysShow: true,
        //    threshold: 5,
        //    placement: 'bottom'
        //});

        var _$storageInformationForm = null;

        function _findAssignedAlcCodeNames() {
            var assignedAlcCodeNames = [];

            _modalManager.getModal()
                .find('.user-role-checkbox-list input[type=checkbox]')
                .each(function () {
                    if ($(this).is(':checked')) {
                        assignedAlcCodeNames.push($(this).attr('name'));
                    }
                });

            return assignedAlcCodeNames;
        }

        this.init = function (modalManager) {
            _modalManager = modalManager;
			            _$storageInformationForm = _modalManager.getModal().find("form[name=storageInformationsForm]");

        }
        
        this.save = function () {
            if (!_$storageInformationForm.valid()) {
                return;
            }
            //校验通过
            var assignedAlcCodeNames = _findAssignedAlcCodeNames();
            var storage = _$storageInformationForm.serializeFormToObject();
          //  console.log(storage);

            _modalManager.setBusy(true);

            _storageService.createOrUpdateStorageAsync({
                storageEditDto: storage,
                assignedAlcCodeNames: assignedAlcCodeNames,
            }).done(function () {
                //提示信息
                abp.notify.info(app.localize('SavedSuccessfully'));
                //关闭窗体
                _modalManager.close();
                //信息保存成功后调用事件，刷新列表
                abp.event.trigger('app.createOrEditStorageModalSaved');
            }).always(function () {
                _modalManager.setBusy(false);
            });
        }
    }
})(jQuery);

   